<?php
/*
 module:		分类表
 create_time:	2024-03-11 10:24:01
 author:		
 contact:		
*/

namespace app\api\controller;

use app\api\model\Category as CategoryModel;

class Category extends Common
{

    /*start*/
    /**
     * @api {get} /Category/index 01、首页数据列表
     */
    function index()
    {
        $field = 'c_id,c_alias,c_name';
        $orderby = 'c_order asc';
        $allCat = CategoryModel::where("c_id", ">", 0)->field($field)->order($orderby)->select()->toArray();
        $res["trade"] = []; //行业分类
        $res["companyType"] = []; //公司类型分类
        $res["wage"] = []; //薪资分类
        $res["jobsNature"] = []; //人员分类
        $res["education"] = [];//学历分类
        $res["experience"] = [];//工作经验分类
        $res["scale"] = [];//公司规模分类
        $res["jobtag"] = [];//公司福利分类
        $res["age"] = [];//年龄分类
        $res["language"] = [];//语言分类
        $res["resumetag"] = [];//自我评价分类
        foreach ($allCat as $al) {
            if ($al["c_alias"] == "QS_trade") $res["trade"][] = $al;
            if ($al["c_alias"] == "QS_company_type") $res["companyType"][] = $al;
            if ($al["c_alias"] == "QS_wage") $res["wage"][] = $al;
            if ($al["c_alias"] == "QS_jobs_nature") $res["jobsNature"][] = $al;
            if ($al["c_alias"] == "QS_education") $res["education"][] = $al;
            if ($al["c_alias"] == "QS_experience") $res["experience"][] = $al;
            if ($al["c_alias"] == "QS_scale") $res["scale"][] = $al;
            if ($al["c_alias"] == "QS_jobtag") $res["jobtag"][] = $al;
            if ($al["c_alias"] == "QS_age") $res["age"][] = $al;
            if ($al["c_alias"] == "QS_language") $res["language"][] = $al;
            if ($al["c_alias"] == "QS_resumetag") $res["resumetag"][] = $al;
        }
        //身份分类
        $res["memberType"] = memberType();
        //求职类型分类
        $categoryjobs_list = \app\api\model\Categoryjobs::where("parentid", 0)->field("id,parentid,categoryname")->order('category_order asc')->select()->toArray();
        $categoryjobs_list2 = \app\api\model\Categoryjobs::where("parentid", ">", 0)->field("id,parentid,categoryname")->order('category_order asc')->select()->toArray();
        foreach ($categoryjobs_list as &$li) {
            $children = [];
            foreach ($categoryjobs_list2 as $key1 => $li2) {
                if ($li2["parentid"] == $li["id"]) {
                    $vas = $li2;
                    $children2 = [];
                    foreach ($categoryjobs_list2 as $key2 => $li3) {
                        if ($li3["parentid"] == $vas["id"]) {
                            $children2[] = $li3;
                            unset($categoryjobs_list2[$key2]);
                        }
                    }
                    $vas["children"] = $children2;
                    $children[] = $vas;
                    unset($categoryjobs_list2[$key1]);
                }
            }
            $li["children"] = $children;
        }
        $res["categoryjobs"] = $categoryjobs_list;
        $res["newWage"] = newWage();
        $res["upTime"] = upTime();
        return $this->ajaxReturn($this->successCode, '返回成功', $res);
    }

    /*end*/
}

